<?php
namespace Home\Model;
use Think\Model;
class AjaxModel extends Model{
protected $tableName = 'promoter_dataoke_product';


	public function CheckQuan($GoodsID)
	{//查找券
		$sql = "select ID,GoodsID,SellerID,Quan_id from ".C('DB_PREFIX')."dataoke_product where GoodsID = '".$GoodsID."'";
		$data = $this->query($sql);	
		//$data = $this->execute($sql);	
		if($data)
		{
			return $data[0];
		}
		else
		{
			return false;
		}
		
	
	}
	public function GetKouling($qunid,$goodsid)
	{
		$sql = "select A.goodsId,A.groupId,A.sclick,B.D_title,B.Pic,C.PID
		from ".C('DB_PREFIX')."fansbuy_sclick as A 
		LEFT JOIN ".C('DB_PREFIX')."dataoke_product as B ON A.goodsId=B.GoodsID
		LEFT JOIN ".C('DB_PREFIX')."promoter as C ON A.groupId=C.groupId
		where A.groupId = '$qunid' and A.goodsid = '$goodsid' LIMIT 1
		";
		//echo $sql;
		//file_put_contents("test.txt",$sql,FILE_APPEND);
		$data = $this->query($sql);	
		//$data = $this->execute($sql);	
		if($data)
		{
			return $data[0];
		}
		else
		{
			return false;
		}
	}
	public function UpdateKouling($fansKongling,$qunid,$goodsid)
	{//更新ajax的口令
		$sql = "Update ".C('DB_PREFIX')."fansbuy_sclick SET fansKongling='".$fansKongling."' where groupId = '".$qunid."' and goodsId = '".$goodsid."'";
		//$data = $this->query($sql);	
		$data = $this->execute($sql);	
		if($data)
		{
			return true;
		}
		else
		{
			return false;
		}	
	}
	public function GetDTKid($GoodsID)
	{
		$sql = "select ID,GoodsID from ".C('DB_PREFIX')."dataoke_product where GoodsID = '".$GoodsID."'";
		$data = $this->query($sql);	
		//$data = $this->execute($sql);	
		if($data)
		{
			return $data[0];
		}
		else
		{
			return false;
		}		
	}
	public function ApplyPay($goodsid,$ordernumber,$qun)
	{
		//先查询是否有人恶意操作 只查询 订单结算 且 payStatus 为0的数据，其他数据忽略
		$sql = "select id from ".C('DB_PREFIX')."reportform where goodsId = '".$goodsid."' and orderNumber = '".$ordernumber."' and groupName = '".$qun."'";
		$data = $this->query($sql);	
		if($data)
		{
			$data = $data[0];
			$id =$data['id'];//有值进行更新操作
			$sql = "Update ".C('DB_PREFIX')."reportform SET payStatus='1' where id = '".$id."'";
			$data = $this->execute($sql);
			if($data)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}	
	
	}




        
}



?>